package com.zj.osm.view.project.projectdetail.fragment.scheme;

import com.zj.osm.entity.greendao.PowerSupplyScheme;
import com.zj.osm.entity.greendao.PowerSupplySchemeDetails;
import com.zj.osm.entity.greendao.Project;
import com.zj.osm.mvp.BasePresenter;

import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.List;

/**
 * 供电方案presenter
 *
 * @author jiang zhu on 2019/10/30
 */
public class PowerSupplySchemePresenter extends BasePresenter<PowerSupplySchemeView> {

    private PowerSupplySchemeModel powerSupplySchemeModel;

    PowerSupplySchemePresenter(){
        this.powerSupplySchemeModel = new PowerSupplySchemeModel();
    }


    public void initData(@Nullable Long projectId) {
        Project project = powerSupplySchemeModel.getProject(projectId);
        PowerSupplyScheme powerSupplyScheme = powerSupplySchemeModel.getPowerSupplyScheme(project);
        List<PowerSupplySchemeDetails> powerSupplySchemeDetailsList = powerSupplySchemeModel.getPowerSupplySchemeModelList(powerSupplyScheme.getId());
        if (getView()!=null){
            getView().initData(project,powerSupplyScheme,powerSupplySchemeDetailsList);
        }
    }

    public void exportWord(@Nullable Long projectId) {
        PowerSupplyScheme powerSupplyScheme = powerSupplySchemeModel.getPowerSupplySchemeById(projectId);
        List<PowerSupplySchemeDetails> powerSupplySchemeDetailsList = powerSupplySchemeModel.getPowerSupplySchemeModelList(powerSupplyScheme.getId());
        HashMap<String,Object> map = powerSupplySchemeModel.createWordFile(powerSupplyScheme,powerSupplySchemeDetailsList);

        if (getView()!=null){
            getView().exportWord(map,powerSupplyScheme,powerSupplySchemeDetailsList);
        }
    }
}
